home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / base / netkit-b.07a / netkit-b / NetKit-B-0.07A / talk / init_disp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-20  |  4.4 KB  |  158 lines

  1. /*
  2.  * Copyright (c) 1983 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. /*
  35.  * From: @(#)init_disp.c    5.4 (Berkeley) 6/1/90
  36.  */
  37. char id_rcsid[] = 
  38.   "$Id: init_disp.c,v 1.4 1996/07/20 20:59:41 dholland Exp $";
  39.  
  40. /*
  41.  * Initialization code for the display package,
  42.  * as well as the signal handling routines.
  43.  */
  44.  
  45. #include <stdio.h>
  46. #include <unistd.h>
  47. #include <signal.h>
  48. #include <termios.h>
  49.  
  50. #include "talk.h"
  51.  
  52. void sig_sent();
  53.  
  54. /* 
  55.  * Set up curses, catch the appropriate signals,
  56.  * and build the various windows.
  57.  */
  58. void
  59. init_display(void)
  60. {
  61.     struct sigaction sigac;
  62.  
  63.     LINES = COLS = 0;
  64.     if (initscr() == NULL) {
  65.         printf("initscr failed: TERM is unset or unknown terminal type.\n");
  66.         exit(-1);
  67.     }
  68.     (void) sigaction(SIGTSTP, NULL, &sigac);
  69.     sigac.sa_mask |= sigmask(SIGALRM);
  70.     (void) sigaction(SIGTSTP, &sigac, NULL);
  71.     curses_initialized = 1;
  72.     clear();
  73.     refresh();
  74.     noecho();
  75.     crmode();
  76.     signal(SIGINT, sig_sent);
  77.     signal(SIGPIPE, sig_sent);
  78.     /* curses takes care of ^Z */
  79.     signal(SIGTSTP, SIG_DFL);    /* No, it doesn't. */
  80.     my_win.x_nlines = LINES / 2;
  81.     my_win.x_ncols = COLS;
  82.     my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0);
  83.     scrollok(my_win.x_win, FALSE);
  84.     wclear(my_win.x_win);
  85.  
  86.     his_win.x_nlines = LINES / 2 - 1;
  87.     his_win.x_ncols = COLS;
  88.     his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols,
  89.         my_win.x_nlines+1, 0);
  90.     scrollok(his_win.x_win, FALSE);
  91.     wclear(his_win.x_win);
  92.  
  93.     line_win = newwin(1, COLS, my_win.x_nlines, 0);
  94.     box(line_win, '-', '-');
  95.     wrefresh(line_win);
  96.     /* let them know we are working on it */
  97.     current_state = "No connection yet";
  98. }
  99.  
  100. /*
  101.  * Trade edit characters with the other talk. By agreement
  102.  * the first three characters each talk transmits after
  103.  * connection are the three edit characters.
  104.  */
  105. void
  106. set_edit_chars(void)
  107. {
  108.     char buf[3];
  109.     int cc;
  110.     struct termios tios;
  111.  
  112.     tcgetattr(0, &tios);
  113.     my_win.cerase = tios.c_cc[VERASE];
  114.     my_win.kill = tios.c_cc[VKILL];
  115.     my_win.werase = tios.c_cc[VWERASE];
  116.  
  117.     if (my_win.werase == (char) -1) {
  118.         my_win.werase = '\027';     /* control W */
  119.     }
  120.  
  121.     buf[0] = my_win.cerase;
  122.     buf[1] = my_win.kill;
  123.     buf[2] = my_win.werase;
  124.     cc = write(sockt, buf, sizeof(buf));
  125.     if (cc != sizeof(buf) )
  126.         p_error("Lost the connection");
  127.     cc = read(sockt, buf, sizeof(buf));
  128.     if (cc != sizeof(buf) )
  129.         p_error("Lost the connection");
  130.     his_win.cerase = buf[0];
  131.     his_win.kill = buf[1];
  132.     his_win.werase = buf[2];
  133. }
  134.  
  135. void
  136. sig_sent(void)
  137. {
  138.     message("Connection closing. Exiting");
  139.     quit();
  140. }
  141.  
  142. /*
  143.  * All done talking...hang up the phone and reset terminal thingy
  144.  */
  145. void
  146. quit(void)
  147. {
  148.     if (curses_initialized) {
  149.         wmove(his_win.x_win, his_win.x_nlines-1, 0);
  150.         wclrtoeol(his_win.x_win);
  151.         wrefresh(his_win.x_win);
  152.         endwin();
  153.     }
  154.     if (invitation_waiting)
  155.         send_delete();
  156.     exit(0);
  157. }
  158.